<template>
  <div>
    <Modal
      v-model="visible"
      title="添加成员"
      @on-ok="ok"
      @on-cancel="cancel"
      class-name="centerModel"
      okText="确定"
      width="284"
    >
      <Form :model="form" label-position="top">
        <FormItem label="昵称">
          <Input v-model="form.nick" maxlength="10" placeholder="请输入姓名昵称"></Input>
        </FormItem>
        <FormItem label="登录用户名">
          <Input v-model="form.username" maxlength="20" placeholder="请输入登录用的ID号"></Input>
        </FormItem>
        <FormItem label="密码">
          <Input v-model="form.password" type="password" maxlength="20" placeholder="请输入登录密码"></Input>
        </FormItem>
          <FormItem label="选择部门">
            <Select class="formInput" v-model="form.type" placeholder="请选择部门">
              <Option value="1">医生</Option>
              <Option value="2">营养管理师</Option>
              <Option value="3">运动管理师</Option>
            </Select>
          </FormItem>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="cancel">取消</Button>
        <Button type="primary" @click="ok">确定</Button>
      </div>
    </Modal>
  </div>
  
</template>
<script>
import {systemUserAdd} from '@/api/department'
export default {
  name: 'addDepartmentUser',
  props: {
    show: Boolean,
    addModelData: Object
  },
  data () {
    return {
      visible: this.show,
      form: {
        nick: '',
        username:'',
        password: '',
        type:'',
        department_id: ''
      }
    }
  },
  watch: {
    show (newv, oldv) {
      this.visible = newv
      this.form = {
        nick: '',
        username:'',
        password: '',
        type:'',
        department_id: ''
      };
    }
  },
  mounted () {},
  methods: {
    ok () {
      let {nick,username,password,type,department_id} = this.form;
      if(!nick){
        this.$Message.warning('请输入姓名昵称');
        return
      }
      if(!username){
        this.$Message.warning('请输入登录用的ID号');
        return
      }
      if(!password){
        this.$Message.warning('请输入登录密码');
        return
      }
      if(!type){
        this.$Message.warning('请选择部门');
        return
      }
      systemUserAdd({
        nick,username,password,type,department_id
      }).then(res=>{
        if(res.code == 100000){
          this.$emit('save')
        }else{
          this.$Message.error(res.msg);
        }
      })
      
    },
    cancel () {
      this.$emit('cancel', false)
    },
  }
}
</script>
<style lang="less" scoped>
 
</style>
